#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;
using ll = long long;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int n, x[N], y[N], z[N], a[N];

ll qp(ll x, int t) { ll res = 1; for(; t; t >>= 1, x = x * x % mod) if(t & 1) res = res * x % mod; return res; }

void solve() {
	n = in; rep(i, 1, n) x[i] = in, y[i] = in, z[i] = in;
	bool fl = true; rep(i, 1, n) fl &= x[i] == 1 && y[i] == 1;
	if(n == 1) {
		int tot  = (x[1] + y[1]) % mod;
		if(tot == 0) printf("%d\n", mod);
		else printf("1\n%d\n", z[1] * qp(tot, mod - 2) % mod);
	} else if(fl) {
		int tot = 0;
		rep(i, 1, n) tot = (tot + z[i]) % mod;
		tot = tot * qp(n + 1, mod - 2) % mod;
		puts("1");
		rep(i, 1, n) {
			a[i] = ((z[i] - tot) % mod + mod) % mod;
			printf("%d%c", a[i], " \n"[i == n]);
		}
	} else puts("114514");
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    for(int T = in; T; T--) solve();
}
